#include <iostream>
#include <vector>
using namespace std;

int n, m, k;
int ans;
vector<vector<string>> matrix;
vector<vector<bool>> vi;
string track;

enum dics { Right, Down, Left, Up };

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

bool valid(int x, int y) {
    if (x < 1 || x > n || y < 1 || y > m || vi[x][y]) return 0;
    return 1;
}

bool happy(string& s) {
    int ans = 0;
    int bei = 1;
    for (int i = s.size() - 1; i >= 0; i--) {
        ans += ((s[i] - '0') * bei) % 7;
        bei = (bei * 10) % 7;
    }
    ans %= 7;
    if(ans == 0) return 1;
    return 0;
}

void dfs(int x, int y, int k, dics direction) {
    if (happy(track)) {
        ans++;
        // cout << track << endl;
    }

    for (int i = 0; i < 4; i++) {
        int fx = x + dx[i];
        int fy = y + dy[i];
        if (!valid(fx, fy)) continue;
        if (i == direction) {
            track += matrix[fx][fy];
            vi[fx][fy] = 1;
            dfs(fx, fy, k, direction);
            track = track.substr(0, track.size() - matrix[fx][fy].size());
            vi[fx][fy] = 0;
        } else {
            if (k == 0) continue;
            track += matrix[fx][fy];
            vi[fx][fy] = 1;
            dfs(fx, fy, k - 1, (dics)i);
            track = track.substr(0, track.size() - matrix[fx][fy].size());
            vi[fx][fy] = 0;
        }
    }
}


int main() {
    cin >> n >> m >> k;
    matrix.resize(n + 1, vector<string>(m + 1));
    vi.resize(n + 1, vector<bool>(m + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) { cin >> matrix[i][j]; }
    }
    track += matrix[1][1];
    vi[1][1] = 1;
    dfs(1, 1, k, Right);
    cout << ans << endl;
    return 0;
}

/*
input
2 3 2
79 8 12
31 10 5

output
4
*/